//
//  ScheduleMemberListController.m
//  YunDongAdmin
//
//  Created by lqq on 2018/9/14.
//  Copyright © 2018年 cloudfighting.com. All rights reserved.
//

#import "ScheduleMemberListController.h"
#import "I_Member.h"
#import "ScheduleMemberListCell.h"

@interface ScheduleMemberListController ()
@property (nonatomic, assign) NSInteger dateInt;//
@property (nonatomic, assign) NSInteger timeInt;//
@property (nonatomic, strong) NSMutableArray *dataSource;
@end

@implementation ScheduleMemberListController
#pragma mark Class Method
+ (instancetype)controllWithDateInt:(NSInteger)dateInt timeInt:(NSInteger)timeInt
{
    ScheduleMemberListController *vc = [[ScheduleMemberListController alloc] init];
    vc.dateInt = dateInt;
    vc.timeInt = timeInt;
    return vc;
}


#pragma mark Life Circle
- (void)viewDidLoad
{
    [super viewDidLoad];

    NSMutableString *title = [[NSMutableString alloc] initWithString:[NSString stringWithFormat:@"%ld",(long)_dateInt]];
    [title insertString:@"." atIndex:6];
    [title insertString:@"." atIndex:4];
    self.title = title;
    
    [self configUI];
    [self requestMemberList];
}

#pragma mark UI
- (void)configUI
{
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ScheduleMemberListCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([ScheduleMemberListCell class])];
}

#pragma mark NET
- (void)requestMemberList
{
    [self.view showLoading];
    WeakSelf(self);
    [I_Member requestSchduleMemberListByDateInt:_dateInt timeInt:_timeInt success:^(NSMutableArray *list) {
        [weakself.view hideStatusView];
        weakself.dataSource = list;
        if (list.count == 0) {
            [weakself.view showEmptyingView];
        }
        [weakself.tableView reloadData];
    } failure:^(NSError *error) {
        [weakself.view showError:error refreshBlock:^{
            [weakself requestMemberList];
        }];
    }];
}


#pragma mark UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ScheduleMemberListCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ScheduleMemberListCell class])];
    cell.scheduleMemberDTO = _dataSource[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}



@end
